// 引入 Vue 3 和 Vue Router
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'

// 引入组件
import Login from '../views/login/Login'
import Register from '../views/register/Register'
import Home from '../views/home/Home'
import MainRole from '../views/role/MainRole'
import ListRole from '../views/role/ListRole'
import AddRole from '../views/role/AddRole'
import DeleteRole from '../views/role/DeleteRole'
import EditRole from '../views/role/EditRole'
import EditRole2 from '../views/role/EditRole2'
import MainInterface from '../views/maininterface/MainInterface'
import DistributeRight from '../views/right/DistributeRight'
import AssignRoles from '../views/right/AssignRoles'
import Customer from '../views/customer/Customer'
import ListCustomer from '../views/customer/ListCustomer'
import AddCustomer  from '../views/customer/AddCustomer'
import DeleteCustomer  from '../views/customer/DeleteCustomer'
import EditCustomer  from '../views/customer/EditCustomer'
import EditCustomer2  from '../views/customer/EditCustomer2'
import DraftContract  from '../views/contract/DraftContract'
import  CounterSignContract from '../views/contract/CounterSignContract'
import  CounterSignContract2 from '../views/contract/CounterSignContract2'
import ApproveContract from '../views/contract/ApproveContract'
import ApproveContract2 from '../views/contract/ApproveContract2'
import FinalizeContract  from '../views/contract/FinalizeContract'
import FinalizeContract2  from '../views/contract/FinalizeContract2'
import SignContract  from '../views/contract/SignContract'
import SignContract2  from '../views/contract/SignContract2'
import PendingContractList from '../views/contract/PendingContractList'
import PendingContract from '../views/contract/PendingContract'
import ContractIfo from '../views/contract/ContractIfo'
import DeleteContract from '../views/contract/DeleteContract'
import QueryContract from '../views/contract/QueryContract'
import ViewOpinions from  '../views/contract/ViewOpinions'

import ListUser from '../views/user/ListUser.vue';
import AddUser from '../views/user/AddUser.vue';
import EditUser from '../views/user/EditUser.vue';
import EditUser2 from '../views/user/EditUser2.vue';
import DeleteUser from '../views/user/DeleteUser.vue';
import MainUser from '../views/user/MainUser.vue';

import ContractInformation from '../views/QueryandStatistics/ContractInformation.vue';
import ContractProcess from '../views/QueryandStatistics/ContractProcess.vue';


// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
        path: '/home', // 路径
        component: Home // 跳转到的组件
    },
    {
          path: '/', // 路径
          redirect:'/sign_contract',
        },
    {
      path: '/login', // 路径
      component: Login // 跳转到的组件
    },
    {
      path: '/register', // 路径
      component: Register // 跳转到的组件
    },
    {
     path:'/role',
     component:MainRole
    },
    {path:'/list_role',
    component:ListRole
    },
    {
    path:'/add_role',
    component:AddRole
    },
     {
     path:'/delete_role',
      component:DeleteRole
       },
    {
       path:'/edit_role',
       component:EditRole
    },
    {
        path:'/maininterface',
        component:MainInterface
    },
    {
             path: '/role/edit_role2/:roleName',
           component:EditRole2
        },
         {
                     path: '/right',
                   component:DistributeRight
          },
     {
                 path: '/right/assignRoles/:username',
               component:AssignRoles
            },
     {
          path: '/customer',
       component:Customer
         },
      {path:'/list_customer',
         component:ListCustomer
         },
         {
         path:'/add_customer',
         component:AddCustomer
         },
          {
          path:'/delete_customer',
           component:DeleteCustomer
            },
         {
            path:'/edit_customer',
            component:EditCustomer
         },
        {
                path: '/customer/edit_customer2/:customerName',
                   component:EditCustomer2
         },
           {
                   path:'/draft_contract',
                     component:DraftContract
             },
       {
          path:'/approve_contract',
        component:ApproveContract
    },
     {
              path:'/approve_contract2/:contractName',
            component:ApproveContract2
        },
   {
             path:'/countersign_contract',
           component:CounterSignContract
       },
        {
                    path:'/countersign_contract2/:contractName',
                  component:CounterSignContract2
              },
    {
              path:'/finalize_contract',
            component:FinalizeContract
        },
      {
                 path:'/finalize_contract2/:contractName',
                 component:FinalizeContract2
             },
        {
                  path:'/sign_contract',
                  component:SignContract
              },
               {
                               path:'/sign_contract2/:contractName',
                                component:SignContract2
                            },
        {
                  path:'/pendingContractList',
              component:PendingContractList
     },
        {
                      path:'/pendingContract/:contractName',
                  component:PendingContract
         },
         {
                               path:'/ContractIfo',
                           component:ContractIfo
                  },
        {
                        path: '/delete_contract',
                        component: DeleteContract
                    },
                    {
                        path: '/query_contract',
                        component: QueryContract
                    },
      {
          path: '/user',
          component: MainUser
      },
      {
          path: '/list_user',
          component: ListUser
      },
      {
          path: '/add_user',
          component: AddUser
      },
      {
          path: '/edit_user2/:username',
          component: EditUser2
      },
      {
          path: '/delete_user',
          component: DeleteUser
      },
      {
          path: '/edit_user',
          component: EditUser
      },
      {
        path: '/query_contract_information',
                 component:ContractInformation
             },
          {
                   path: '/query_contract_process',
                   component: ContractProcess
               },
    {
                       path: '/view_opinions/:contractName',
                       component:ViewOpinions
                   },
  ]
})


export default router
// 导航守卫，前置处理
router.beforeEach((to, from, next) => {
let isAuthenticated = !!sessionStorage.getItem('userInfo')
// 如果路由要跳转到除了登录和注册的界面的话就判断是否已经登录，如果没有登录就强制跳到登录界面
if (to.path !== '/login' && to.path !== '/register' && !isAuthenticated) {
next({ path: '/login' })
// 这里 Message 提示需要根据你实际的情况调整
 Message({
 message: '请先登录！',
 type: 'warning',
 });
} else {
next()
}
})
